from click import *
import time


@command()
@argument("list", default=False)
@option("--state", default="all", help="new or done,finish or unfinish")
@option("--created", default="0", help="get data before create_time")
@option("--by", default="0", help="get task list before the time of reference 'state'")
def show_list(list, state, created, by):
    print(f"list:{list}")
    if not list:
        return 0
    check_time_format((created, by))
    todo_tasks = select_by_time(created, by)
    state_to_call(state, todo_tasks)


def state_to_call(state, todo_tasks):
    _dict = {
        "done": call_done,
        "new": call_new
    }
    if _dict.get(state, None):
        func = _dict[state]
        return func(todo_tasks)
    return call_all(todo_tasks)


def call_done(todo_tasks):
    _res = todo_tasks["data"]
    _list = [i for i in _res if i['complete_time'] is not None]
    print(_list)


def call_new(todo_tasks):
    _res = todo_tasks["data"]
    _list = [i for i in _res if i['complete_time'] is None]
    print(_list)


def call_all(todo_tasks):
    _res = todo_tasks["data"]
    print(_res)


def check_time_format(str_time_iterator):
    for str_time in str_time_iterator:
        pass
    return True


def select_by_time(create_time, complete_time):
    return {
        "code": 200,
        "data": [
            {
                "id": 0,
                "name": "test1",
                "create_time": "2021-11-25 18:46:00",
                "complete_time": "2021-11-25 18:46:00",
                "state": None
            },
            {
                "id": 1,
                "name": "test2",
                "create_time": "2021-11-25 18:47:00",
                "complete_time": None,
                "state": "new"
            }
        ],
        "msg": "select ok"
    }


def get_now_time():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())


if __name__ == '__main__':
    show_list()


